<?php
/**
 * Delcampe_Stats
 * 
 * @package Delcampe
 * @author Kamalitha
 * @copyright 2009
 * @version 1.0
 * @access public
 */
class Delcampe_Stats
{
	private $db; 
	
	/**
	 * Delcampe_Stats::__construct()
	 * 
	 * @return void
	 */
	public function __construct() 
  	{ 
  		$this->db = Zend_Registry::get('db'); 
  	}

  	/**
  	 * Delcampe_Stats::getMemberCount()
  	 * 
  	 * @return mixed
  	 */
  	public function getMemberCount()
  	{
  		try 
	  	{
	   		return $this->db->fetchAll("SELECT COUNT(id_member) AS user_count FROM  members",null);
	  	}
	  	catch(Exception $ex)
	  	{
	   		return null;
	  	}
  	}
  	
  	/**
  	 * Delcampe_Stats::getBlogCount()
  	 * 
  	 * @return mixed
  	 */
  	public function getBlogCount()
  	{
  		try 
	  	{
	   		return $this->db->fetchAll("SELECT COUNT(blog_id) AS blog_count FROM  user_blog",null);
	  	}
	  	catch(Exception $ex)
	  	{
	   		return null;
	  	}
  	}
  	
	/**
	 * Delcampe_Stats::getBlogPostCount()
	 * 
	 * @return mixed
	 */
	public function getBlogPostCount()
  	{
  		try 
	  	{
	   		return $this->db->fetchAll("SELECT COUNT(post_id) AS post_count FROM  blog_post WHERE published=1",null);
	  	}
	  	catch(Exception $ex)
	  	{
	   		return null;
	  	}
  	}
  	
  	public function getLatestNews()
  	{
  		try 
	  	{
	   		return $this->db->fetchAll("SELECT resource.id, resource_types.name, resource.mime_type, 
	   									resource.commentable, resource.created_date FROM resource INNER JOIN
	   									resource_types ON resource.resource_type_id=resource_types.resource_type_id 
	   									ORDER BY resource.created_date DESC LIMIT 10",null);
	  	}
	  	catch(Exception $ex)
	  	{
	   		return null;
	  	}
  	}
  	
  	public function getBlogCommentDetails($res_id)
  	{
  		try 
	  	{
	   		return $this->db->fetchAll("select members.firstname,blog_post.post_id, blog_post.post_title,
	   									resource.created_date from comments inner join members on 
	   									comments.user_id=members.id_member inner join blog_post on 
	   									comments.parent_res_id=blog_post.post_id inner join resource 
	   									on comments.comment_id=resource.id where comments.comment_id=?",
	   									$res_id);
	  	}
	  	catch(Exception $ex)
	  	{
	   		return null;
	  	}
  	}
  	
  	public function getBlogPostDetails($res_id)
  	{
  		try 
	  	{
	   		return $this->db->fetchAll("select members.firstname, user_blog.blog_title,user_blog.blog_id,
	   									blog_post.publish_date from blog_post inner join members on
	   									blog_post.user_id=members.id_member inner join user_blog on
	   									blog_post.blog_id=user_blog.blog_id where blog_post.post_id=?",
	   									$res_id);
	  	}
	  	catch(Exception $ex)
	  	{
	   		return null;
	  	}
  	}
  	
	public function getGalleryPhotoDetails($res_id)
  	{
  		try 
	  	{
	   		return $this->db->fetchAll("select gallery_albums.album_id,gallery_photos.photo_id,members.firstname, 
	   									gallery_albums.title, gallery_photos.created from 
	   									gallery_photos inner join gallery_albums on gallery_photos.album_id=gallery_albums.album_id 
	   									INNER join members on gallery_albums.user_id=members.id_member 
	   									where gallery_photos.photo_id=?",
	   									$res_id);
	  	}
	  	catch(Exception $ex)
	  	{
	   		return null;
	  	}
  	}
  	
}
?>